﻿@{
    ViewData["Title"] = "添加广告内容";
    Layout = "~/Areas/Manager/Views/Shared/_Layout.cshtml";
}
<style type="text/css">
    .layui-form-label {
        width:100px;
    }
</style>
<div class="layui-bgn" style="padding-bottom:220px;margin-top:-10px;">
    <form class="layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">基本信息</li>
                <li>扩展信息</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label">广告名称</label>
                        <div class="layui-input-block">
                            <input type="text" style="width:80%" lay-verify="required" name="AdvertisementName" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label">展现方式</label>
                        <div class="layui-input-block">
                            <input id="rbTextContent" lay-filter="rbTextContent" type="radio" name="ContentType" value="0" title="文字" checked="">
                            <input id="rbImgContent" lay-filter="rbImgContent" type="radio" name="ContentType" value="1" title="图片">
                            <input id="rbFlashContent" lay-filter="rbFlashContent" type="radio" name="ContentType" value="2" title="flash">
                            <input id="rbCodeContent" lay-filter="rbCodeContent" type="radio" name="ContentType" value="3" title="代码">
                        </div>
                    </div>
                    <div class="layui-form-item" id="filePath" style="display: none;">
                        <label class="layui-form-label">图片地址</label>
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="img">上传图片</button>
                                <div class="layui-upload-list" style="padding-left:21px;">
                                    <img class="layui-upload-img" id="imgShow" style="width:100px;height:100px;">
                                    <p id="demoText"></p>
                                    <input type="hidden" name="FileUrl" id="FileUrl">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" id="SwffilePath" style="display: none;">
                        <label class="layui-form-label">FLASH地址</label>
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn layui-btn-normal" id="chooseFile">选择文件</button>
                                <button type="button" class="layui-btn" id="commitFile">开始上传</button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" id="AlternateText">
                        <label class="layui-form-label">广告语</label>
                        <div class="layui-input-block">
                            <input type="text" style="width:80%" name="AlternateText" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text" id="advHtml" style="display: none;">
                        <label class="layui-form-label">广告HTML代码</label>
                        <div class="layui-input-block">
                            <textarea name="AdvHtml" class="layui-textarea" style="width:80%"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label">APP业务分类</label>
                        <div class="layui-input-block">
                            <input type="radio" name="OperationType" lay-filter="OperationType" value="url" title="外链接" checked="">
                            <input type="radio" name="OperationType" lay-filter="OperationType" value="product" title="商品详情">
                            <input type="radio" name="OperationType" lay-filter="OperationType" value="category" title="商品分类">
                            <input type="radio" name="OperationType" lay-filter="OperationType" value="suppliershop" title="商家">
                            <input type="radio" name="OperationType" lay-filter="OperationType" value="articledetail" title="文章详情">
                            <input type="radio" name="OperationType" lay-filter="OperationType" value="invite" title="邀请赢话费">
                        </div>
                    </div>
                    <div class="layui-form-item" id="targetid">
                        <label class="layui-form-label"><span id="txtSpan"></span>标识值</label>
                        <div class="layui-input-block">
                            <input type="text" style="width:80%" name="TargetId" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" id="NavigateUrl">
                        <label class="layui-form-label">链接地址</label>
                        <div class="layui-input-block">
                            <input type="text" style="width:80%" name="NavigateUrl" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-block">
                            <input type="checkbox" lay-skin="primary" title="是否有效" lay-filter="Status">
                            <input type="hidden" name="Status" id="Status" value=0 />
                            <input type="hidden" id="AdvPositionId" name="AdvPositionId" value="@ViewBag.AdvPositionId" />
                        </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-form-item">
                        <div class="layui-form-item">
                            <label class="layui-form-label">起始时间</label>
                            <div class="layui-input-block">
                                <input type="text" style="width:50%" name="StartDate" id="StartDate" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">结束时间</label>
                            <div class="layui-input-block">
                                <input type="text" style="width:50%" name="EndDate" id="EndDate" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline" style="width:250px;">
                            <label class="layui-form-label">显示频率</label>
                            <div class="layui-input-inline" style="width:100px;">
                                <input type="text" name="Impressions" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline" style="width:250px;">
                            <label class="layui-form-label">最大浏览量</label>
                            <div class="layui-input-inline" style="width:100px;">
                                <input type="tel" name="DayMaxPv" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline" style="width:250px;">
                            <label class="layui-form-label">最大IP访问</label>
                            <div class="layui-input-inline" style="width:100px;">
                                <input type="text" name="DayMaxIp" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label">到期自动停止</label>
                        <div class="layui-input-block">
                            <input type="radio" name="AutoStop" value="1" title="是" checked="">
                            <input type="radio" name="AutoStop" value="0" title="否">
                            <input type="radio" name="AutoStop" value="-1" title="无限制">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add" id="submit" type="button">提交</button>
                <button id="close" type="button" class="layui-btn layui-btn-primary">关闭</button>
            </div>
        </div>
    </form>
</div>

    @section scriptsfeet
        {
        <script type="text/javascript">

        layui.config({
            base: '/layuiadmin/' //自定义模块路径
        }).use(['laydate', 'upload', 'element','form', 'layer', 'sykjwh'], function () {
            var $ = layui.$
                , form = layui.form
                , sykjwh = layui.sykjwh
                , laydate = layui.laydate //日期
                , layer = layui.layer //弹层
                , upload = layui.upload //上传

            $("#close").click(function () {
                sykjwh.close();
            });

            form.on('checkbox(Status)', function (data) {
                console.log(data.elem.checked); //是否被选中
                if (data.elem.checked) {//判断复选框是否被选中
                    $("#Status").val(1);//如果选中则修改Status的value为1
                } else {
                    $("#Status").val(0);
                }
            });

            form.on('submit(add)', function (obj) {
                //保存
                sykjwh.save('@Url.Action("AdvertisementAdd", "ad", new { area = Constant.AREAMANAGER })', obj.field);
            });

            //单选框监听，根据选择的单选框显示对应的内容
            baseLoad();
            form.on('radio(rbTextContent)', function () {
               baseLoad();
            });
            form.on('radio(rbImgContent)', function () {
                baseLoad();
            });
            form.on('radio(rbFlashContent)', function () {
                baseLoad();
            });
            form.on('radio(rbCodeContent)', function () {
                baseLoad();
            });
            form.on('radio(OperationType)', function () {
                baseLoad();
            });

            function baseLoad() {
                var checkVal = $(":radio[name='ContentType']:checked").val();
                if (checkVal == 0) {
                    $("#filePath").hide();
                    $("#SwffilePath").hide();
                    $("#advHtml").hide();
                    $("#AlternateText").show();
                }
                if (checkVal == 1) {
                    $("#filePath").show();
                    $("#advHtml").hide();
                    $("#SwffilePath").hide();
                    $("#AlternateText").show();
                }
                if (checkVal == 2) {
                    $("#filePath").hide();
                    $("#SwffilePath").show();
                    $("#advHtml").hide();
                    $("#AlternateText").hide();
                }
                if (checkVal == 3) {
                    $("#filePath").hide();
                    $("#SwffilePath").hide();
                    $("#advHtml").show();
                    $("#AlternateText").hide();
                }
                //App业务类型
                var $obj = $(":radio[name='OperationType']:checked");
                var value = $obj.val();
                var text = $.trim($obj.next().children("div").text());
                $("#txtSpan").text(text);

                if (value == "url") {
                    $("#NavigateUrl").show();
                    $("#targetid").hide();
                } if (value == "product") {
                    $("#NavigateUrl").hide();
                    $("#targetid").show();
                } if (value == "category") {
                    $("#NavigateUrl").hide();
                    $("#targetid").show();
                } if (value == "suppliershop") {
                    $("#NavigateUrl").hide();
                    $("#targetid").show();
                } if (value == "articledetail") {
                    $("#NavigateUrl").hide();
                    $("#targetid").show();
                } if (value == "invite") {
                    $("#NavigateUrl").show();
                    $("#targetid").hide();
                } 
            }

            //日期
            laydate.render({
                elem: '#StartDate'
            });
            laydate.render({
                elem: '#EndDate'
            });

            //普通图片上传
            upload.render({
                elem: '#img'
                , url: "@BaseConfig.ImagesDoMain"+'/Upload/Images'
                , done: function (res) {
                    if (res.success === true) {
                        //上传成功
                        $("#FileUrl").val(res.data.path);
                        $('#imgShow').attr('src', "@BaseConfig.ImagesDoMain"+res.data.path);
                    }
                    else {
                        return layer.msg(res.msg);
                    }
                }
            });

            //选完文件后不自动上传
            upload.render({
                elem: '#chooseFile'
                , url: '/Upload/Files'
                , auto: false
                //,multiple: true
                , bindAction: '#commitFile'
                , done: function (res) {
                    if (res.success === true) {
                        //上传成功
                        $("#FileUrl").val(res.data.path);
                    }
                    else {
                        return layer.msg(res.msg);
                    }
                }
            });
        });
        </script>
    }
